<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="./template.xhtml">

            <ui:define name="title">
                <c:choose>
                    <c:when test="#{empty receptView.recept}">
                        Kuchařka - Nový recept
                    </c:when>
                    <c:otherwise>
                        Kuchařka - úprava #{receptView.recept.nazev}
                    </c:otherwise>
                </c:choose>
            </ui:define>

            <ui:define name="breadcrumbs">
                <h:commandLink action="index" value="Kuchařka"/> > 
                <h:commandLink action="recepty" value="Seznam receptů"/> > 
                <c:choose>
                    <c:when test="#{empty receptView.recept}">
                        Nový recept
                    </c:when>
                    <c:otherwise>
                        <h:commandLink action="#{receptView.showReceptDetail(receptView.recept)}" value="#{receptView.recept.nazev}"/> > 
                         Editace
                    </c:otherwise>
                </c:choose>
                
                
            </ui:define>
            
            <ui:define name="heading">
                <h:form>
                    <h:inputText class="form-control" id="nazev" maxlength="10" value="#{receptView.recept.nazev}" required="" style="font-size:40px; height:69px" p:placeholder="Název receptu"/>
                </h:form>
            </ui:define>

            <ui:define name="subheading">
                <c:choose>
                    <c:when test="#{empty receptView.recept}">
                        <p>Pro vytvoření nového receptu vyplňte všechna pole a klepněte na tlačítko "Uložit".</p>
                    </c:when>
                    <c:otherwise>
                        <p>Změny po úpravě receptu potvrdíte klepnutím na tlačítko "Uložit".</p>
                    </c:otherwise>
                </c:choose>
            </ui:define>

            <ui:define name="content">
                <h:form>
                <table width="100%">
                    <tr>
                        <td align="left">
                            <h3>
                                Seznam ingrediencí
                            </h3>
                        </td>
                        <td align="right">
                            <h3>    
                                <h:form>
                                    <h:commandLink type="submit" class="btn btn-xs btn-primary">
                                        <span class="glyphicon glyphicon-floppy-save"></span>Uložit
                                    </h:commandLink>

                                    <h:commandLink type="submit" class="btn btn-xs btn-danger">
                                        <span class="glyphicon glyphicon-remove"></span> Zahodit změny
                                    </h:commandLink>
                                </h:form>
                            </h3>
                        </td>
                    </tr>
                </table>
                
                
                    
                    <c:choose>
                        <c:when test="#{empty receptView.recept}">
                            <h:dataTable 
                             style="border-collapse: separate; border-spacing: 10px;"
                             >
                                <h:column>
                                    <h:inputText class="form-control" required="" p:placeholder="Množství"/>
                                </h:column>

                                <h:column>
                                    <h:inputText class="form-control" required="" p:placeholder="Název ingredience"/>
                                </h:column>

                                    <h:column>
                                <h:commandLink type="submit" class="btn btn-xs btn-danger">
                                    <span class="glyphicon glyphicon-remove"/>Odstranit řádek
                                </h:commandLink>
                                </h:column>
                                <f:facet name="footer">
                                    <h:commandLink type="submit" class="btn btn-xs btn-primary">
                                        <span class="glyphicon glyphicon-plus"></span> Přidat řádek
                                    </h:commandLink>
                                </f:facet>
                            </h:dataTable>
                        </c:when>
                        <c:otherwise>
                            <h:dataTable value="#{receptView.toList(receptView.recept.seznamIngredienci)}" var="entry"
                             style="border-collapse: separate; border-spacing: 10px;"
                            >
                            
                            <h:column>
                                <h:inputText class="form-control" value="#{entry.value.mnozstvi}#{entry.value.jednotka}" required="" p:placeholder="Množství"/>
                            </h:column>

                            <h:column>
                                <h:inputText class="form-control" value="#{entry.key.nazev}" required="" p:placeholder="Název ingredience"/>
                            </h:column>
                            <h:column>
                            <h:commandLink type="submit" class="btn btn-xs btn-danger">
                                <span class="glyphicon glyphicon-remove"/>Odstranit řádek
                            </h:commandLink>
                            </h:column>
                            <f:facet name="footer">
                                <h:commandLink type="null" class="btn btn-xs btn-primary">
                                    <span class="glyphicon glyphicon-plus"></span> Přidat řádek
                                </h:commandLink>
                            </f:facet>
                            </h:dataTable>
                        </c:otherwise>
                        </c:choose>

		<h3>
	  		Postup
		</h3>
                    <h:inputTextarea rows="5" value="#{receptView.recept.postup}" style="width: 100%" p:placeholder="Postup vaření"/>
		</h:form>
            </ui:define>
            

        </ui:composition>

    </body>
</html>
